package psn.qiuyiping.autocad.dxffile;

import java.util.Map;

@Dxf0Name("TABLE")
@SubClassName("AcDbSymbolTable")
public class DxfTable extends DxfObject {
    String                      name;
    @DxfCode(70)
    int                         count;
    Map<String, DxfTableRecord> records;

    public DxfTable() {
        super();
        records = new java.util.TreeMap<>();
        fields.putAll(redo(DxfTable.class));
    }

    @DxfCode(2)
    public void readDxf2(DxfProcessContext context, DxfData<String> item) {
        this.name = (String) item.getVal();
        if ("LAYER".equals(name)) {
            this.records = (Map) context.getFile().layers;
        } else if ("LTYPE".equals(name)) {
            this.records = (Map) context.getFile().ltypes;
        } else if ("STYLE".equals(name)) {
            this.records = (Map) context.getFile().textStyles;
        } else if ("DIMSTYLE".equals(name)) {
            this.records = (Map) context.getFile().dimStyles;
        }
        context.setCurrentTable(this);
    }

    public void addRecord(DxfTableRecord record) {
        records.put(record.name, record);
    }

}
